package com.lanou3g.baidumusic.main.musicfragment.recommendfragment;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou3g.baidumusic.R;
import com.squareup.picasso.Picasso;

/**
 * Created by dllo on 17/3/25.
 */

public class RecyclerViewSixAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private RecommendRecyclerViewBean bean;
    private SixHolder sixHolder;
    private TenHolder tenHolder;
    private int type;

    public void setRecommendSixRecyclerViewBean(RecommendRecyclerViewBean bean) {
        this.bean = bean;
        notifyDataSetChanged();
    }

    public RecyclerViewSixAdapter(Context context, int type) {
        this.context = context;
        this.type = type;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (type) {
            case 6:
                View view6 = LayoutInflater.from(context).inflate(R.layout.item_fragment_recommend_six_rv_rv, parent, false);
                sixHolder = new SixHolder(view6);
                return sixHolder;
            case 10:
                View view10 = LayoutInflater.from(context).inflate(R.layout.item_fragment_recommend_ten_rv_rv, parent, false);
                tenHolder = new TenHolder(view10);
                return tenHolder;
        }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        switch (type) {
            case 6:
                SixHolder sixHolder = (SixHolder) holder;
                sixHolder.textView1.setText(bean.getResult().getRecsong().getResult().get(position).getTitle());
                sixHolder.textView2.setText(bean.getResult().getRecsong().getResult().get(position).getAuthor());
                Picasso.with(context).load(bean.getResult().getRecsong().getResult().get(position).getPic_premium()).into(sixHolder.imageView);
                break;
            case 10:
                TenHolder tenHolder = (TenHolder) holder;
                tenHolder.textView1.setText(bean.getResult().getMod_7().getResult().get(position).getTitle());
                tenHolder.textView2.setText(bean.getResult().getMod_7().getResult().get(position).getDesc());
                Picasso.with(context).load(bean.getResult().getMod_7().getResult().get(position).getPic()).into(tenHolder.imageView);
                break;
        }
        if (6 == position) {
            tenHolder.blankTv.setVisibility(View.VISIBLE);
            Log.d("ListFragmentAdapter", "blankTv");
        }

    }


    @Override
    public int getItemCount() {

        if (null == bean) {
            return 0;
        }
        if (null == bean.getResult()) {
            return 0;
        }

        switch (type) {
            case 6:
                return bean.getResult() != null && bean.getResult().getRecsong().getResult().size() > 0 ? 3 : 0;
            case 10:
                return bean.getResult() != null && bean.getResult().getMod_7().getResult().size() > 0 ? 7 : 0;

        }

        return 0;
    }


    public class SixHolder extends RecyclerView.ViewHolder {

        TextView textView1, textView2;
        ImageView imageView;

        public SixHolder(View itemView) {
            super(itemView);
            textView1 = (TextView) itemView.findViewById(R.id.item_fragment_recommend_six_rv_rv_tv1);
            textView2 = (TextView) itemView.findViewById(R.id.item_fragment_recommend_six_rv_rv_tv2);
            imageView = (ImageView) itemView.findViewById(R.id.item_fragment_recommend_six_rv_rv_iv);

        }
    }

    public class TenHolder extends RecyclerView.ViewHolder {

        TextView textView1, textView2, blankTv;
        ImageView imageView;

        public TenHolder(View itemView) {
            super(itemView);
            textView1 = (TextView) itemView.findViewById(R.id.item_fragment_recommend_ten_rv_tv1);
            textView2 = (TextView) itemView.findViewById(R.id.item_fragment_recommend_ten_rv_tv2);
            imageView = (ImageView) itemView.findViewById(R.id.item_fragment_recommend_ten_rv_iv);
            blankTv = (TextView) itemView.findViewById(R.id.item_fragment_recommend_blank_tv);
        }
    }

}
